package service

import (
	"context"
	"insighttracking/query/dao"
)

type _areaService struct {
}

func (s _areaService) GetAreaNameApi(ctx context.Context, code string) (name string, err error) {
	areaEntity, err := dao.AreaEntity.WithContext(ctx).Where(dao.AreaEntity.Code.Eq(code)).First()
	if err != nil {
		return "", err
	}
	return areaEntity.Address, nil
}

func (s _areaService) GetAreaCodeApi(ctx context.Context, name string) (code string, err error) {
	areaEntity, err := dao.AreaEntity.WithContext(ctx).Where(dao.AreaEntity.Name.Eq(name)).First()
	if err != nil {
		return "", err
	}
	return areaEntity.Code, nil
}

var AreaService = new(_areaService)
